<template>

    <view :style="{'height':windowHeight, 'width':windowWidth,'background-color':'#F1F1F1'}">
        <view>

            <uni-row>
                <uni-col :span="20">
                    <view><uni-search-bar :radius="100" v-model="searchWord" @input="fetchQuestionRecords" @confirm="search" placeholder="台站名称"></uni-search-bar></view>
                </uni-col>
                <uni-col :span="3"><view></view></uni-col>
                <uni-col :span="1">
                    <view style="margin-top: 0.5rem; margin-left: 0.5rem; ">
                        <uni-icons type="plusempty" size="30" @click="navigateToQuestionRecord()" ></uni-icons>
                    </view>
                </uni-col>
            </uni-row>
            <view>
                <scroll-view>
                    <uni-list >
                        <view v-for="questionRecord in questionRecords" :key="questionRecord.stationCode">
                            <uni-list-chat
                                    v-bind:title="questionRecord.stationCode + ' ' + questionRecord.stationName"
                                    v-bind:note="questionRecord.question"
                                    v-bind:time="questionRecord.questionDate"
                                    clickable="true"
                                    @click="navigateToRepairRecordInfo(questionRecord.id)"
                                    v-bind:stationCode="questionRecord.stationCode"
                            ></uni-list-chat>
                        </view>
                    </uni-list>
                </scroll-view>
            </view>
        </view>
    </view>
    
</template>

<script>
    export default {
        name: "QuestionFeedbackMain",
        data() {
            return {
                windowWidth: '375px',
                windowHeight: '667px',
                stationCode: '',
                searchWord: '',
                questionRecords:[
                    {
                        id: '1',
                        stationCode: 'G1121',
                        stationName: '笋岗',
                        questionDate: '2021-11-23 09:00:11',
                        questionContent: 'WSP3103',
                        questionIsDeal: '',
                    }
                ]
            }
        },
        onLoad: function(options) {
            this.windowWidth = options.windowWidth
            this.windowHeight = options.windowHeight
            this.stationCode = options.stationCode

            this.fetchQuestionRecords()
        },
        methods: {
            fetchQuestionRecords() {

                uni.showLoading({
                    title: '问题反馈'
                })
                this.stationCode = this.stationCode === undefined ? '' : this.stationCode
                this.searchWord = this.searchWord === undefined ? '' : this.searchWord
                this.uniRequest({
                    url: '/stations/questions',
                    data: {
                        stationCode: this.stationCode,
                        searchWord: this.searchWord
                    },
                    method: 'GET',
                }).then((res) => {
                    console.log('fetchAllCheckRecords Response: ', res)
                    this.questionRecords = res.data;
                    uni.hideLoading()
                }).catch((err) => {
                    console.log('fetchAllCheckRecords error: ', err)
                    uni.hideLoading()
                    uni.showToast({
                        icon: 'error',
                        title: '问题反馈列表获取失败！ ',
                        duration: 2000
                    })
                });
            },
            navigateToRepairRecordInfo(recordId) {
                uni.navigateTo({
                    url: '/pages/question/QuestionRecordInfo?windowHeight=' + this.windowHeight + '&windowWidth=' + this.windowWidth + '&recordId=' + recordId

                })
            },
            navigateToQuestionRecord() {
                uni.navigateTo({
                    url: '/pages/question/QuestionRecordUpdate?windowHeight=' + this.windowHeight + '&windowWidth=' + this.windowWidth + '&action=create&stationCode=' + this.stationCode
                })
            }
        }
    }
</script>

<style scoped>

</style>